* Boston, MA 02111-1307, USA.
*/
+/* This loader is very hairy code.
+ *
+ * The main loop was not designed for incremental loading, so when it was hacked
+ * in it got a bit messy. Basicly, every function is written to expect a failed
+ * read_gif, and lets you call it again assuming that the bytes are there.
+ *
+ * A note on Animations:
+ * It actually wouldn't be that hard to add support for Gif Animations. You'd
+ * need, of course, to get the necessary info from the extension, and read the
+ * private colormap into it's own frame, instead of context->color_map. You'd
+ * also need to stop it from moving to GIF_DONE at the end of gif_get_lzw, (and
+ * of course generate the necessary frames.
+ *
+ * Return vals.
+ * Unless otherwise specified, these are the return vals for most functions:
+ *
+ * 0 -> success
+ * -1 -> more bytes needed.
+ * -2 -> failure; abort the load
+ * -3 -> control needs to be passed back to the main loop
+ * \_ (most of the time returning 0 will get this, but not always)
+ * >1 -> for functions that get a guchar, the char will be returned.
+ *
+ * -jrb (11/03/1999)
+ */
+
+/*
+ * If you have any images that crash this code, please, please let me know and
+ * send them to me.
+ * <jrb@redhat.com>
+ */
+
#include <config.h>
#include <stdio.h>
#include <glib.h>
static int count = 0;
#endif
-/* Returns TRUE if Read is OK,
+/* Returns TRUE if read is OK,
* FALSE if more memory is needed. */
static int
-ReadOK (GifContext *context, guchar *buffer, size_t len)
+gif_read (GifContext *context, guchar *buffer, size_t len)
{
gint retval;
#ifdef IO_GIFDEBUG
}
-/*
- * Return vals.
- * Unless otherwise specified, these are the return vals for most functions:
- *
- * 0 -> success
- * -1 -> more bytes needed.
- * -2 -> failure; abort the load
- * -3 -> control needs to be passed back to the main loop
- * \_ (most of the time returning 0 will get this, but not always)
- */
-
-
/* Changes the stage to be GIF_GET_COLORMAP */
static void
unsigned char rgb[3];
while (context->colormap_index < context->bit_pixel) {
- if (!ReadOK (context, rgb, sizeof (rgb))) {
+ if (!gif_read (context, rgb, sizeof (rgb))) {
/*g_message (_("GIF: bad colormap\n"));*/
return -1;
}
{
if (context->block_count == 0) {
- if (!ReadOK (context, &context->block_count, 1)) {
+ if (!gif_read (context, &context->block_count, 1)) {
return -1;
}
}
return 0;
}
- if (!ReadOK (context, buf, context->block_count)) {
+ if (!gif_read (context, buf, context->block_count)) {
return -1;
}
if (context->extension_label == 0) {
/* I guess bad things can happen if we have an extension of 0 )-: */
/* I should look into this sometime */
- if (!ReadOK (context, & context->extension_label , 1)) {
+ if (!gif_read (context, & context->extension_label , 1)) {
return -1;
}
}
{
// unsigned char count;
- if (!ReadOK (context, &context->block_count, 1)) {
+ if (!gif_read (context, &context->block_count, 1)) {
/*g_message (_("GIF: error in getting DataBlock size\n"));*/
return -1;
}
ZeroDataBlock = context->block_count == 0;
- if ((context->block_count != 0) && (!ReadOK (context, buf, context->block_count))) {
+ if ((context->block_count != 0) && (!gif_read (context, buf, context->block_count))) {
/*g_message (_("GIF: error in reading DataBlock\n"));*/
return -1;
}
{
gint i;
- if (!ReadOK (context, &(context->lzw_set_code_size), 1)) {
+ if (!gif_read (context, &(context->lzw_set_code_size), 1)) {
/*g_message (_("GIF: EOF / read error on image data\n"));*/
return -1;
}
unsigned char buf[16];
char version[4];
- if (!ReadOK (context, buf, 6)) {
+ if (!gif_read (context, buf, 6)) {
/* Unable to read magic number */
return -1;
}
}
/* read the screen descriptor */
- if (!ReadOK (context, buf, 7)) {
+ if (!gif_read (context, buf, 7)) {
/* Failed to read screen descriptor */
return -1;
}
gif_get_frame_info (GifContext *context)
{
unsigned char buf[9];
- if (!ReadOK (context, buf, 9)) {
+ if (!gif_read (context, buf, 9)) {
return -1;
}
/* Okay, we got all the info we need. Lets record it */
{
unsigned char c;
while (TRUE) {
- if (!ReadOK (context, &c, 1)) {
+ if (!gif_read (context, &c, 1)) {
return -1;
}
if (c == ';') {